using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Design;

namespace Evaluant.EussDSL
{
    /// <summary>
    /// The CustomTypeDescriptor is used to filter the properties displayed
    /// when manipulating an Id of an Entity
    /// </summary>
    internal class CustomTypeDescriptor : ElementTypeDescriptor
    {
        private ModelElement _element = null;

        #region Constructors
        public CustomTypeDescriptor(ModelElement element)
            : base(element)
        {
            this._element = element;
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Returns the property descriptors for this descriptor. The properties are filtered
        /// depending on the name of the generator.
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            //Get default properties
            PropertyDescriptorCollection descriptors = base.GetProperties(attributes);
            //Do your filtering here, you can change the descriptors (i.e make change property), or remove them from collection. 
            PropertyDescriptor generatorNamePD = null;
            int parc = 0;
            PropertyDescriptor sizePD = null, dbTypePD = null, seedPD = null, incrementPD = null;
            foreach (PropertyDescriptor descriptor in descriptors)
            {
                if (descriptor.Name.ToLower() == "generatorname")
                {
                    generatorNamePD = descriptor;
                }

                if (descriptor.Name.ToLower() == "size")
                {
                    sizePD = descriptor;
                }
                if (descriptor.Name.ToLower() == "dbtype")
                {
                    dbTypePD = descriptor;
                }
                if (descriptor.Name.ToLower() == "seed")
                {
                    seedPD = descriptor;
                }
                if (descriptor.Name.ToLower() == "increment")
                {
                    incrementPD = descriptor;
                }

                parc++;
            }

            if (generatorNamePD != null && sizePD != null && dbTypePD != null && seedPD != null && incrementPD != null)
            {
                switch (generatorNamePD.GetValue(this).ToString())
                {
                    case "guid":
                        descriptors.Remove(sizePD);
                        descriptors.Remove(dbTypePD);
                        descriptors.Remove(seedPD);
                        descriptors.Remove(incrementPD);
                        break;
                    case "native":
                        descriptors.Remove(sizePD);
                        break;
                    case "assigned":
                        descriptors.Remove(seedPD);
                        descriptors.Remove(incrementPD);
                        break;
                    case "inherited":
                        descriptors.Remove(sizePD);
                        descriptors.Remove(dbTypePD);
                        descriptors.Remove(seedPD);
                        descriptors.Remove(incrementPD);
                        break;
                    case "business":
                        descriptors.Remove(sizePD);
                        descriptors.Remove(dbTypePD);
                        descriptors.Remove(seedPD);
                        descriptors.Remove(incrementPD);
                        break;
                    default:
                        break;
                }
            }

            return descriptors;
        }
        #endregion
    }
}

